/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.me.mahjongcalc.controller;

import org.me.mahjongcalc.error.MPlayerNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.me.mahjongcalc.model.MHand;

/**
 *
 * @author xelinis
 */
public class MController {

	private MController() {}

	private static String dealer = null;
	private static Map<String, MHand> players =
			new HashMap<String, MHand>();

	public static MHand getHand( String player )
			throws MPlayerNotFoundException {

		if ( !getPlayers().contains( player ) ) {
			throw new MPlayerNotFoundException( player );
		}

		return players.get( player );
	}

	public static Set<String> getPlayers() {

		return players.keySet();
	}

	public static void addPlayer( String name ) {
		if ( name != null ) {
			players.put( name, new MHand() );
			if ( dealer == null ) {
				dealer = name;
			}
		}
	}

	public static void setDealer( String player )
			throws MPlayerNotFoundException {

		if ( !getPlayers().contains( player ) ) {
			throw new MPlayerNotFoundException( player );
		}

		dealer = player;
	}

	public static String getDealer() {

		return dealer;
	}

}
